import apiClient from './auth';

// 获取提示词列表
export const getPrompts = async (params = {}) => {
  try {
    const response = await apiClient.get('/prompts/prompts/', { params });
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 获取提示词详情
export const getPromptDetail = async (id) => {
  try {
    const response = await apiClient.get(`/prompts/prompts/${id}/`);
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 创建提示词
export const createPrompt = async (promptData) => {
  try {
    const response = await apiClient.post('/prompts/prompts/', promptData);
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 更新提示词
export const updatePrompt = async (id, promptData) => {
  try {
    const response = await apiClient.put(`/prompts/prompts/${id}/`, promptData);
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 删除提示词
export const deletePrompt = async (id) => {
  try {
    const response = await apiClient.delete(`/prompts/prompts/${id}/`);
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 批量删除提示词
export const batchDeletePrompts = async (ids) => {
  try {
    const response = await apiClient.post('/prompts/prompts/batch_delete/', { ids });
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 复制提示词
export const copyPrompt = async (id) => {
  try {
    const response = await apiClient.post(`/prompts/prompts/${id}/copy/`);
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 获取提示词统计信息
export const getPromptStats = async () => {
  try {
    const response = await apiClient.get('/prompts/prompts/stats/');
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 获取标签列表
export const getTags = async (search = '') => {
  try {
    const response = await apiClient.get('/prompts/tags/', { params: { search } });
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 创建标签
export const createTag = async (tagData) => {
  try {
    const response = await apiClient.post('/prompts/tags/', tagData);
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};

// 获取AI模型列表
export const getAIModels = async () => {
  try {
    const response = await apiClient.get('/prompts/ai-models/');
    return response.data;
  } catch (error) {
    throw error.response ? error.response.data : error;
  }
};